clc 
clear all
close all

prks70_1 = GetFairnessIndex('PRKS70_stable_pdr_rd1.txt');
prks70_2 = GetFairnessIndex('PRKS70_stable_pdr_rd2.txt');
prks70_3 = GetFairnessIndex('PRKS70_stable_pdr_rd3.txt');
prks70_4 = GetFairnessIndex('PRKS70_stable_pdr_rd4.txt');
prks70_5 = GetFairnessIndex('PRKS70_stable_pdr_rd5.txt');
prks70 = [prks70_1, prks70_2,prks70_3,prks70_4,prks70_5];

prks80_1 = GetFairnessIndex('PRKS80_stable_pdr_rd1.txt');
prks80_2 = GetFairnessIndex('PRKS80_stable_pdr_rd2.txt');
prks80_3 = GetFairnessIndex('PRKS80_stable_pdr_rd3.txt');
prks80_4 = GetFairnessIndex('PRKS80_stable_pdr_rd4.txt');
prks80_5 = GetFairnessIndex('PRKS80_stable_pdr_rd5.txt');
prks80 = [prks80_1, prks80_2,prks80_3,prks80_4,prks80_5];

prks90_1 = GetFairnessIndex('PRKS90_stable_pdr_rd1.txt');
prks90_2 = GetFairnessIndex('PRKS90_stable_pdr_rd2.txt');
prks90_3 = GetFairnessIndex('PRKS90_stable_pdr_rd3.txt');
prks90_4 = GetFairnessIndex('PRKS90_stable_pdr_rd4.txt');
prks90_5 = GetFairnessIndex('PRKS90_stable_pdr_rd5.txt');
prks90 = [prks90_1, prks90_2,prks90_3,prks90_4,prks90_5];

prks95_1 = GetFairnessIndex('PRKS95_stable_pdr_rd1.txt');
prks95_2 = GetFairnessIndex('PRKS95_stable_pdr_rd2.txt');
prks95_3 = GetFairnessIndex('PRKS95_stable_pdr_rd3.txt');
prks95_4 = GetFairnessIndex('PRKS95_stable_pdr_rd4.txt');
prks95_5 = GetFairnessIndex('PRKS95_stable_pdr_rd5.txt');
prks95 = [prks95_1, prks95_2,prks95_3,prks95_4,prks95_5];

rid70_1 = GetFairnessIndex('RID70_stable_pdr_rd1.txt');
rid70_2 = GetFairnessIndex('RID70_stable_pdr_rd2.txt');
rid70_3 = GetFairnessIndex('RID70_stable_pdr_rd3.txt');
rid70_4 = GetFairnessIndex('RID70_stable_pdr_rd4.txt');
rid70_5 = GetFairnessIndex('RID70_stable_pdr_rd5.txt');
rid70 = [rid70_1, rid70_2,rid70_3,rid70_4,rid70_5];

rid80_1 = GetFairnessIndex('RID80_stable_pdr_rd1.txt');
rid80_2 = GetFairnessIndex('RID80_stable_pdr_rd2.txt');
rid80_3 = GetFairnessIndex('RID80_stable_pdr_rd3.txt');
rid80_4 = GetFairnessIndex('RID80_stable_pdr_rd4.txt');
rid80_5 = GetFairnessIndex('RID80_stable_pdr_rd5.txt');
rid80 = [rid80_1, rid80_2,rid80_3,rid80_4,rid80_5];

rid90_1 = GetFairnessIndex('RID90_stable_pdr_rd1.txt');
rid90_2 = GetFairnessIndex('RID90_stable_pdr_rd2.txt');
rid90_3 = GetFairnessIndex('RID90_stable_pdr_rd3.txt');
rid90_4 = GetFairnessIndex('RID90_stable_pdr_rd4.txt');
rid90_5 = GetFairnessIndex('RID90_stable_pdr_rd5.txt');
rid90 = [rid90_1, rid90_2,rid90_3,rid90_4,rid90_5];

rid95_1 = GetFairnessIndex('RID95_stable_pdr_rd1.txt');
rid95_2 = GetFairnessIndex('RID95_stable_pdr_rd2.txt');
rid95_3 = GetFairnessIndex('RID95_stable_pdr_rd3.txt');
rid95_4 = GetFairnessIndex('RID95_stable_pdr_rd4.txt');
rid95_5 = GetFairnessIndex('RID95_stable_pdr_rd5.txt');
rid95 = [rid95_1, rid95_2,rid95_3,rid95_4,rid95_5];

cmac70_1 = GetFairnessIndex('CMAC70_stable_pdr_rd1.txt');
cmac70_2 = GetFairnessIndex('CMAC70_stable_pdr_rd2.txt');
cmac70_3 = GetFairnessIndex('CMAC70_stable_pdr_rd3.txt');
cmac70_4 = GetFairnessIndex('CMAC70_stable_pdr_rd4.txt');
cmac70_5 = GetFairnessIndex('CMAC70_stable_pdr_rd5.txt');
cmac70 = [cmac70_1, cmac70_2,cmac70_3,cmac70_4,cmac70_5];

cmac80_1 = GetFairnessIndex('CMAC80_stable_pdr_rd1.txt');
cmac80_2 = GetFairnessIndex('CMAC80_stable_pdr_rd2.txt');
cmac80_3 = GetFairnessIndex('CMAC80_stable_pdr_rd3.txt');
cmac80_4 = GetFairnessIndex('CMAC80_stable_pdr_rd4.txt');
cmac80_5 = GetFairnessIndex('CMAC80_stable_pdr_rd5.txt');
cmac80 = [cmac80_1, cmac80_2,cmac80_3,cmac80_4,cmac80_5];

cmac90_1 = GetFairnessIndex('CMAC90_stable_pdr_rd1.txt');
cmac90_2 = GetFairnessIndex('CMAC90_stable_pdr_rd2.txt');
cmac90_3 = GetFairnessIndex('CMAC90_stable_pdr_rd3.txt');
cmac90_4 = GetFairnessIndex('CMAC90_stable_pdr_rd4.txt');
cmac90_5 = GetFairnessIndex('CMAC90_stable_pdr_rd5.txt');
cmac90 = [cmac90_1, cmac90_2,cmac90_3,cmac90_4,cmac90_5];

cmac95_1 = GetFairnessIndex('CMAC95_stable_pdr_rd1.txt');
cmac95_2 = GetFairnessIndex('CMAC95_stable_pdr_rd2.txt');
cmac95_3 = GetFairnessIndex('CMAC95_stable_pdr_rd3.txt');
cmac95_4 = GetFairnessIndex('CMAC95_stable_pdr_rd4.txt');
cmac95_5 = GetFairnessIndex('CMAC95_stable_pdr_rd5.txt');
cmac95 = [cmac95_1, cmac95_2,cmac95_3,cmac95_4,cmac95_5];


csma_1 = GetFairnessIndex('CSMA_stable_pdr_rd1.txt');
csma_2 = GetFairnessIndex('CSMA_stable_pdr_rd2.txt');
csma_3 = GetFairnessIndex('CSMA_stable_pdr_rd3.txt');
csma_4 = GetFairnessIndex('CSMA_stable_pdr_rd4.txt');
csma_5 = GetFairnessIndex('CSMA_stable_pdr_rd5.txt');
csma = [csma_1, csma_2,csma_3,csma_4,csma_5];

rtscts_1 = GetFairnessIndex('RTSCTS_stable_pdr_rd1.txt');
rtscts_2 = GetFairnessIndex('RTSCTS_stable_pdr_rd2.txt');
rtscts_3 = GetFairnessIndex('RTSCTS_stable_pdr_rd3.txt');
rtscts_4 = GetFairnessIndex('RTSCTS_stable_pdr_rd4.txt');
rtscts_5 = GetFairnessIndex('RTSCTS_stable_pdr_rd5.txt');
rtscts = [rtscts_1, rtscts_2,rtscts_3,rtscts_4,rtscts_5];

scream_1 = GetFairnessIndex('SCREAM_stable_pdr_rd1.txt');
scream_2 = GetFairnessIndex('SCREAM_stable_pdr_rd2.txt');
scream_3 = GetFairnessIndex('SCREAM_stable_pdr_rd3.txt');
scream_4 = GetFairnessIndex('SCREAM_stable_pdr_rd4.txt');
scream_5 = GetFairnessIndex('SCREAM_stable_pdr_rd5.txt');
scream = [scream_1, scream_2,scream_3,scream_4,scream_5];


ALPHA=0.05;

MEAN = zeros(4,6);
Error_MEAN = zeros(4,6);
MEAN(1,1) = mean(prks70);
MEAN(1,2) = mean(csma);
MEAN(1,3) = mean(rtscts);
MEAN(1,4) = mean(rid70);
%MEAN(1,5) = mean(iOrder70);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks70) / sqrt(size(prks70, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(1,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid70) / sqrt(size(rid70, 1));
MEAN(1,5) = mean(cmac70);
Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac70) / sqrt(size(cmac70, 1));
MEAN(1,6) = mean(scream);
Error_MEAN(1,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));
%Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(iOrder70) / sqrt(size(iOrder70, 1));
MEAN(2,1) = mean(prks80);
MEAN(2,2) = mean(csma);
MEAN(2,3) = mean(rtscts);
MEAN(2,4) = mean(rid80);
%MEAN(2,5) = mean(iOrder80);

Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks80) / sqrt(size(prks80, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(2,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid80) / sqrt(size(rid80, 1));
MEAN(2,5) = mean(cmac80);
Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac80) / sqrt(size(cmac80, 1));
MEAN(2,6) = mean(scream);
Error_MEAN(2,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));
%Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(iOrder80) / sqrt(size(iOrder80, 1));
MEAN(3,1) = mean(prks90);
MEAN(3,2) = mean(csma);
MEAN(3,3) = mean(rtscts);
MEAN(3,4) = mean(rid90);
%MEAN(3,5) = mean(iOrder90);

Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks90) / sqrt(size(prks90, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(3,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid90) / sqrt(size(rid90, 1));
MEAN(3,5) = mean(cmac90);
Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac90) / sqrt(size(cmac90, 1));
MEAN(3,6) = mean(scream);
Error_MEAN(3,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));
%Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(iOrder90) / sqrt(size(iOrder90, 1));
MEAN(4,1) = mean(prks95);
MEAN(4,2) = mean(csma);
MEAN(4,3) = mean(rtscts);
MEAN(4,4) = mean(rid95);
%MEAN(4,5) = mean(iOrder95);

Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks95) / sqrt(size(prks95, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(4,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid95) / sqrt(size(rid95, 1));
MEAN(4,5) = mean(cmac95);
Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac95) / sqrt(size(cmac95, 1));
MEAN(4,6) = mean(scream);
Error_MEAN(4,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));
%Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(iOrder95) / sqrt(size(iOrder95, 1));

figure;
handle = barweb(MEAN, Error_MEAN,1, ['70%';'80%';'90%';'95%'], [], ['PDR requirement'], ['Jain''s fairness index'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS', 'RIDB','CMAC','SCREAM','orientation','horizontal');
%hp = findobj(handle.bars,'type','patch');
%hatchfill(hp(1),'cross');
set(gca,'fontsize',60);
box on
maximize ();

[im_hatch, colorlist]=applyhatch_pluscolor(gcf, '/-\xkc',1,[1 1 1 1 0 1],[],[],5,10);
